package Algorithm;

public class BackTrack {
    private void show(int[] arr){
        for (int i:arr){
            System.out.print(i+" ");
        }
        System.out.println();
    }
    //子集树
    private int[] arr={-1,-1,-1,-1};
    private void backtrack1(int t){
        if (t>3){
            show(arr);
        }else {
            for (int i=0;i<=1;i++){
                arr[t]=i;
                backtrack1(t+1);
            }
        }
    }
    //排序树
    private int[] arr2={1,2,3,4};
    private void backtrack2(int t) {
        if (t > 3) {
            show(arr2);
        } else {
            for (int i = t; i <= 3; i++) {
                int temp = arr2[t];
                arr2[t] = arr2[i];
                arr2[i] = temp;
                backtrack2(t + 1);
                temp = arr2[i];
                arr2[i] = arr2[t];
                arr2[t] = temp;
            }
        }
    }
    public static void main(String[] args) {
        BackTrack bt=new BackTrack();
        bt.backtrack1(0);
        System.out.println("----------------");
        bt.backtrack2(1);
    }
}
